package ui.map {
	
	import common.MapData;
	import common.loader.BaseLoader;
	
	import flash.display.BitmapData;
	import flash.utils.Dictionary;
	
	import globals.Global;
	import globals.Setting;

	public class MapManager {
		
		private var mapList:Dictionary;
		public var arena:Arena;
		private var path:Array;

		public function MapManager() {
			mapList = new Dictionary();
			arena = new Arena();
//			arena.x = 50;
//			arena.y = 50;
			Global.game.sceneLayer.addChildAt(arena, 0);
		}
		
		public function initMap(mapData:MapData):void {
			path = mapData.path;
			arena.update(mapData.tiles);
			var items:Array = [
				["item_1",0,3], ["item_1",1,3], ["item_1",2,3], ["item_1",3,3],
				["item_1",0,6], ["item_1",1,6], ["item_1",2,6], ["item_1",3,6],
				["item_1",15,1], ["item_1",16,1], ["item_1",17,1], ["item_1",18,1],
				["item_1",16,3], ["item_1",17,3], ["item_1",18,3],
				["item_1",18,4], ["item_1",18,5], ["item_1",18,6], ["item_1",18,7]
			];
			arena.updateItems(items);
		}
		
		public function loadMap(mid:String):void {
//			var loader:BaseLoader = new BaseLoader(Setting.SERVER_HOST + "");
//			loader.handler = mapHandler;
//			loader.start();
		}
		
		private function mapHandler(loader:BaseLoader):void {
//			initMap(loader.data as MapData);
		}
		
		public function getPath():Array {
//			return path;
			return [
				[0,4], [1,4], [2, 4], [3, 4], [4, 4], [5, 4], 
				[5,5], [5,6], [5,7], [5,8],
				[6,8], [7,8], [8,8], 
				[8,7], [8,6], 
				[9,6], [10,6], [11,6], [12,6], [13,6],
				[13,7], [13,8], [13,9], [13,10],
				[14,10], [15,10],
				[15,9], [15,8], [15,7], [15,6], [15,5], [15,4], [15,3], [15,2],
				[17,2], [18,2], [19,2]
			];
		}
		
		public function getBuildList():Array {
			return [
				[0,4], [1,4], [2, 4], [3, 4], [4, 4], [5, 4], [6,4], [7,4], [8, 4], [9, 4], [10, 4], [11, 4]
			];
		}
		
		public function clear():void {
			path = new Array();
			arena.clear();
		}
	}
}